﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

[assembly: log4net.Config.DOMConfigurator(ConfigFile = "../../../../BaseLib/LogException/Resources/log4net.config", Watch = true)]
namespace LogException
{
    /// <summary>
    /// 日志辅助类 Create by xyli
    /// </summary>
    public class LogUtil
    {
        #region 输出Info日志到Log4Net
        /// <summary>
        /// 输出Info日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="ex"></param>
        public static void WriteLog_Info(Type t, Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Info("info", ex);
        }

        /// <summary>
        /// 输出Info日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="msg"></param>
        public static void WriteLog_Info(Type t, string msg)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Info(msg);
        }

        #endregion

        #region 输出Warn日志到Log4Net
        /// <summary>
        /// 输出Warn日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="ex"></param>
        public static void WriteLog_Warn(Type t, Exception ex, string userName)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Warn("Error", ex);
        }

        /// <summary>
        /// 输出Warn日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="msg"></param>
        public static void WriteLog_Warn(Type t, string msg)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Warn(msg);
        }

        #endregion

        #region 输出Debug日志到Log4Net
        /// <summary>
        /// 输出Debug日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="ex"></param>
        public static void WriteLog_Debug(Type t, Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Debug("Debug", ex);
        }

        /// <summary>
        /// 输出Debug日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="msg"></param>
        public static void WriteLog_Debug(Type t, string msg)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Debug(msg);
        }

        #endregion

        #region 输出Error日志到Log4Net
        /// <summary>
        /// 输出Debug日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="ex"></param>
        public static void WriteLog_Error(Type t, Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Error("Error", ex);
        }

        /// <summary>
        /// 输出Debug日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="msg"></param>
        public static void WriteLog_Error(Type t, string msg)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Error(msg);
        }


        #endregion

        #region 输出Fatal致命错误日志到Log4Net
        /// <summary>
        /// 输出Fatal错误日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="ex"></param>
        public static void WriteLog_Fatal(Type t, Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Fatal("Fatal", ex);
        }

        /// <summary>
        /// 输出Fatal错误日志到Log4Net
        /// </summary>
        /// <param name="t"></param>
        /// <param name="msg"></param>
        public static void WriteLog_Fatal(Type t, string msg)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(t);
            log.Fatal(msg);
        }

        #endregion
    }
}
